package com.itheima.myfile.test2;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;


public class ServerDemo {
    public static void main(String[] args) throws IOException {
        //创建Serversocket对象
        ServerSocket ss = new ServerSocket(10000);
        //与客户端创建链接
        Socket accept = ss.accept();
        //读取数据
        InputStream is = accept.getInputStream();
        //定义数组读取快
        byte[] bytes = new byte[1024];
        int len;
        while ((len = is.read(bytes))!=-1){
            System.out.println(new String(bytes,0,len));
        }


        //接收到信息给客户端一个反馈信息,字符反馈用转换流
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
        bw.write("你谁呀?孙贼");
        //刷新关闭流
        bw.newLine();
        bw.flush();

        //关闭流
        ss.close();
        bw.close();

    }
}
